iT邦幫忙

2022 iThome 鐵人賽

DAY 16
0
自我挑戰組

Android Studio、Photoshop入門系列 第 16

Android Studio入門-D16 認識Kotlin語法(3)

  • 分享至 

  • xImage
  •  

接著昨天的程式碼

 when (position) {
            0 ->  {
                    val view = inflater.inflate(R.layout.fragment_1, container, false)
                    val btn_contact = view.findViewById<Button>(R.id.btn_contact)
                    val textView3= view.findViewById<TextView>(R.id.textView3)
                    btn_contact.setOnClickListener {
                        //textView.text="ABC"
                        AlertDialog.Builder(this.context)
                            .setTitle("聯繫方式")
                            .setMessage("我的信箱:409570157@gapp.fju.edu.tw ")
                            .setPositiveButton("確認"){dialog, _ ->
                                dialog.dismiss()
                            }
                            .show()
                        parentFragmentManager.setFragmentResultListener("freg2",this){
                            freg2,bundle-> textView3.text = bundle.getString("mainMeal")
                        }
                       }
                       return view
                    }
            1 ->   {
                    val view = inflater.inflate(R.layout.fragment_2, container, false)
                val send = view.findViewById<Button>(R.id.send)
                val mealA: CheckBox = view.findViewById(R.id.checkBox)
                val mealB: CheckBox = view.findViewById(R.id.checkBox2)
                val mealC: CheckBox = view.findViewById(R.id.checkBox3)
                val mealD: CheckBox = view.findViewById(R.id.checkBox4)
                send.setOnClickListener {
                    //3.1 判斷哪個check buton被勾選(可複選)
                    val meal1 = if (mealA.isChecked) "A餐" else ""
                    val meal2 = if (mealB.isChecked) "B餐" else ""
                    val meal3 = if (mealC.isChecked) "C餐" else ""
                    val meal4 = if (mealD.isChecked) "D餐" else ""
                    val meal = "$meal1 $meal2 $meal3 $meal4"

                    //3.2 將點餐項目存入bundle
                    val bundle = Bundle()
                    bundle.putString("mainMeal", meal)

                    //3.3 透過setResult將資料回傳呼叫頁(主頁)
                    parentFragmentManager.setFragmentResult("freg2",bundle)
                }
                    return view
                    }
            else -> {
                    val view = inflater.inflate(R.layout.fragment_3, container, false)

                    return view
                    }
            }
        }

那Android Studio 就到這邊啦~
明天要講甚麼呢?
敬請期待


結果我還是躲不過確診風波/images/emoticon/emoticon70.gif
確了....../images/emoticon/emoticon22.gif


上一篇
Android Studio入門-D15 認識Kotlin語法(2)
下一篇
Photoshop入門-Day17 介紹&下載
系列文
Android Studio、Photoshop入門30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言